package com.tenebrous.jestic.constants;

/**
 * <p/>
 * Description:
 * <p/>
 * REST接口返回的结果状态码,这些结果状态码参照HTTP协议
 */
public enum ResultCode {
    C200(200, "操作成功"),
    C401(401, "No Login"),
    C403(403, "Forbidden"),
    C404(404, "Not Found"),
    C406(406, "参数有误"),
    C500(500, "系统异常");
    public int code;
    public String desc;

    ResultCode(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ResultCode format(String name) {
        for (ResultCode value : ResultCode.values()) {
            if (name.equals(value.toString())) {
                return value;
            }
        }
        return null;

    }

    public static ResultCode formatName(int valKey) {
        for (ResultCode value : ResultCode.values()) {
            if (valKey == value.getCode()) {
                return value;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
}
